<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/29 0029
 * Time: 上午 8:11
 */

namespace Home\Controller;

use Think\Controller;

class LoginController extends Controller
{
    public function index()
    {
        $this->display();
    }

    public function login()
    {
//        $username=$_REQUEST['username'];
//        $password=$_REQUEST['password'];
        $username = I('username');
        $password = I('password');
        $user = M('admin')->where("Aname='{$username}'")->find();

//        var_dump($user);
        if (!$user) {
            $this->error('没有该用户', U('Login/index'), 3);
        }
        if ($user['apassword'] == $password) {
//            $_SESSION['username'] = $username;
            //使用thinkPHP session支持
            session('username', $username);
            $this->success('登录成功', U('Emplist/index'), 3);
        } else {
            $this->error('密码错误');
        }

    }



    public function logout()
    {
//        unset($_SESSION);
//        session_destroy();
        session(null);
        $this->success('退出成功', U('login/index'),3);

    }
}